//
// Created by f12160c on 2018/6/15.
//
#include <iostream>
#include <vector>
#include<gtest/gtest.h>

#include "leetcode/leetcode.hpp"

using namespace std;

namespace {
    class TestLeetcode : public ::testing::Test {
    public:
        virtual void SetUp() {
            cout << "SetUp" << endl;
        }

        virtual void TearDown() {
            cout << "TearDown" << endl;
        }
    };

    TEST_F(TestLeetcode, Test_threeSum) {
        vector intput = {-1, 0, 1, 2, -1, -4};
        vector<vector<int>> expect_output = {{-1, -1,  2}, {-1, 0, 1}};

        auto acture_output = Solution::threeSum(intput);
        ASSERT_EQ(expect_output.size(), acture_output.size());

        for(auto elm: acture_output)
        {
            sort(elm.begin(), elm.end());
        }
        sort(acture_output.begin(), acture_output.end(), [](vector<int> x, vector<int> y)->bool {
            if(x[0] < y[0])
            {
                return true;
            }
            else if(x[0] == y[0])
            {
                if(x[1] < y[1])
                {
                    return true;
                }
                else if(x[1] == y[1])
                {
                    return x[2] < y[2];
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        });

        for(int i = 0; i < acture_output.size(); i++)
        {
            ASSERT_EQ(expect_output[i], acture_output[i]);
        }
    }
}
